let selection = require("selection");
let contextMenu = require("context-menu");

contextMenu.add(contextMenu.Menu({
  label: "Statusus",
  context: function() { return selection.text ? true : false },
  items: [
    contextMenu.Item({ 
      label: "Twitter",
      onClick: function() {
        if(selection.text.length > 130) {
          require('tabs').activeTab.contentWindow.alert("Length of the selected texts is too large. Maximum allowed is 130 symbols. :)");
        } else {
          require('tabs').open("http://twitter.com/share?url=" + require("tabs").activeTab.location + "&via=Statusus&text=" + selection.text);
        }
      }
    }),
    contextMenu.Item({ 
      label: "Facebook",
      onClick: function() {
        if(selection.text.length > 420) {
          require('tabs').activeTab.contentWindow.alert("Length of the selected texts is too large. Maximum allowed is 420 symbols. :)");
        } else {
          require('tabs').open("http://www.facebook.com/dialog/feed?app_id=158809844165673&redirect_uri=http://facebook.com&message=" + selection.text);
        }
      }
    })
  ]
}));
